package com.compiler.lexico.token;

import java.util.Collection;
import java.util.HashSet;
import java.util.Vector;

import com.compiler.logger.TokenPipe;


public class SymbolTable {
	private Collection<Token> symbols;
	private TokenPipe tokenPipe; //Guardo todo los tokens para pasarlos al Sintactico
	private Collection<Object> reservedWords;
	
	public SymbolTable(Vector<Object> reservedWords) {
		this.symbols = new HashSet<Token>();
		this.tokenPipe = new TokenPipe();
		this.reservedWords = reservedWords;
	}
	
	public void addToken(Token token) {
		this.symbols.add(token); //No agrega repetidos
		this.tokenPipe.addToken(token); //Agrega todo
	}

	public Object[] getSymbolTable() {
		return this.symbols.toArray();
	}
	
	public TokenPipe getTokenPipe() {
		return this.tokenPipe;
	}
	
	public boolean isReservedWord(Token token) {
		return this.reservedWords.contains(token.getData());
	}
	
	public String toString() {
		String ret = "################## Tabla de Simbolos("+this.symbols.size()+ ") ##################\n" +
					 "[Nro. Linea: TOKEN	--->	TIPO]\n";
		for(Token t : this.symbols)
			ret += "Linea #"+t.getLine()+": "+t.getData()+" ---> "+t.getType()+"\n";
		return ret;
	}
}
